#include "Frm06.h"

Frm06::Frm06(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm06::~Frm06() {
}

void Frm06::onInit() {

}

void Frm06::createParts() {
	setMainArg(0, 0, 1024, 600);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- MButton : wMMButton1                 -----------------------------*/
	wMMButton1 = new STTButton(p_rt, this, "wMMButton1", 1);
	wMMButton1->setMainArg(0, 0, 93, 97, false);
	wMMButton1->setImg("1", "./images/arrow_34_93X97.gray.svg", "");
	wMMButton1->setImg("0", "./images/arrow_34_93X97.svg", "");
	wMMButton1->bindOpenFormHandler(Event::CLICKED, "Frm01", PageMode::NEWWIN, NULL);

	/*----------------------------- Button : wMButton1                   -----------------------------*/
	wMButton1 = new STTButton(p_rt, this, "wMButton1", 0);
	wMButton1->setMainArg(192, 1, 98, 48, false);
	wMButton1->setPressedArg("正常便便", 0x0, "文泉驿微米黑", 16, 0);
	wMButton1->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton1->setReleasedArg("正常便便", 0x0, "文泉驿微米黑", 12, 0);
	wMButton1->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton2                   -----------------------------*/
	wMButton2 = new STTButton(p_rt, this, "wMButton2", 0);
	wMButton2->setMainArg(93, 1, 98, 48, false);
	wMButton2->setPressedArg("全部图集", 0x0, "文泉驿微米黑", 16, 0);
	wMButton2->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton2->setReleasedArg("全部图集", 0x0, "文泉驿微米黑", 12, 0);
	wMButton2->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton3                   -----------------------------*/
	wMButton3 = new STTButton(p_rt, this, "wMButton3", 0);
	wMButton3->setMainArg(291, 1, 98, 48, false);
	wMButton3->setPressedArg("沙门氏菌", 0x0, "文泉驿微米黑", 16, 0);
	wMButton3->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton3->setReleasedArg("沙门氏菌", 0x0, "文泉驿微米黑", 12, 0);
	wMButton3->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton4                   -----------------------------*/
	wMButton4 = new STTButton(p_rt, this, "wMButton4", 0);
	wMButton4->setMainArg(390, 1, 98, 48, false);
	wMButton4->setPressedArg("念珠菌", 0x0, "文泉驿微米黑", 16, 0);
	wMButton4->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton4->setReleasedArg("念珠菌", 0x0, "文泉驿微米黑", 12, 0);
	wMButton4->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton5                   -----------------------------*/
	wMButton5 = new STTButton(p_rt, this, "wMButton5", 0);
	wMButton5->setMainArg(489, 1, 98, 48, false);
	wMButton5->setPressedArg("毛滴虫、球虫", 0x0, "文泉驿微米黑", 16, 0);
	wMButton5->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton5->setReleasedArg("毛滴虫、球虫", 0x0, "文泉驿微米黑", 12, 0);
	wMButton5->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton6                   -----------------------------*/
	wMButton6 = new STTButton(p_rt, this, "wMButton6", 0);
	wMButton6->setMainArg(588, 1, 98, 48, false);
	wMButton6->setPressedArg("念珠细毛滴虫", 0x0, "文泉驿微米黑", 16, 0);
	wMButton6->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton6->setReleasedArg("念珠细毛滴虫", 0x0, "文泉驿微米黑", 12, 0);
	wMButton6->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton7                   -----------------------------*/
	wMButton7 = new STTButton(p_rt, this, "wMButton7", 0);
	wMButton7->setMainArg(687, 1, 98, 48, false);
	wMButton7->setPressedArg("大肠杆菌", 0x0, "文泉驿微米黑", 16, 0);
	wMButton7->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton7->setReleasedArg("大肠杆菌", 0x0, "文泉驿微米黑", 12, 0);
	wMButton7->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton8                   -----------------------------*/
	wMButton8 = new STTButton(p_rt, this, "wMButton8", 0);
	wMButton8->setMainArg(786, 1, 98, 48, false);
	wMButton8->setPressedArg("霉菌", 0x0, "文泉驿微米黑", 16, 0);
	wMButton8->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton8->setReleasedArg("霉菌", 0x0, "文泉驿微米黑", 12, 0);
	wMButton8->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton9                   -----------------------------*/
	wMButton9 = new STTButton(p_rt, this, "wMButton9", 0);
	wMButton9->setMainArg(885, 1, 98, 48, false);
	wMButton9->setPressedArg("肠毒", 0x0, "文泉驿微米黑", 16, 0);
	wMButton9->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton9->setReleasedArg("肠毒", 0x0, "文泉驿微米黑", 12, 0);
	wMButton9->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton10                  -----------------------------*/
	wMButton10 = new STTButton(p_rt, this, "wMButton10", 0);
	wMButton10->setMainArg(93, 50, 98, 48, false);
	wMButton10->setPressedArg("新城疫腺病毒", 0x0, "文泉驿微米黑", 16, 0);
	wMButton10->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton10->setReleasedArg("新城疫腺病毒", 0x0, "文泉驿微米黑", 12, 0);
	wMButton10->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton11                  -----------------------------*/
	wMButton11 = new STTButton(p_rt, this, "wMButton11", 0);
	wMButton11->setMainArg(192, 50, 98, 48, false);
	wMButton11->setPressedArg("溃疡性肠炎", 0x0, "文泉驿微米黑", 16, 0);
	wMButton11->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton11->setReleasedArg("溃疡性肠炎", 0x0, "文泉驿微米黑", 12, 0);
	wMButton11->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton12                  -----------------------------*/
	wMButton12 = new STTButton(p_rt, this, "wMButton12", 0);
	wMButton12->setMainArg(291, 50, 98, 48, false);
	wMButton12->setPressedArg("道菌群失衡", 0x0, "文泉驿微米黑", 16, 0);
	wMButton12->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton12->setReleasedArg("道菌群失衡", 0x0, "文泉驿微米黑", 12, 0);
	wMButton12->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton13                  -----------------------------*/
	wMButton13 = new STTButton(p_rt, this, "wMButton13", 0);
	wMButton13->setMainArg(390, 50, 98, 48, false);
	wMButton13->setPressedArg("嗉囊炎", 0x0, "文泉驿微米黑", 16, 0);
	wMButton13->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton13->setReleasedArg("嗉囊炎", 0x0, "文泉驿微米黑", 12, 0);
	wMButton13->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton14                  -----------------------------*/
	wMButton14 = new STTButton(p_rt, this, "wMButton14", 0);
	wMButton14->setMainArg(489, 50, 98, 48, false);
	wMButton14->setPressedArg("啄羽、咬毛", 0x0, "文泉驿微米黑", 16, 0);
	wMButton14->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton14->setReleasedArg("啄羽、咬毛", 0x0, "文泉驿微米黑", 12, 0);
	wMButton14->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton15                  -----------------------------*/
	wMButton15 = new STTButton(p_rt, this, "wMButton15", 0);
	wMButton15->setMainArg(588, 50, 98, 48, false);
	wMButton15->setPressedArg("鹦鹉喙羽病", 0x0, "文泉驿微米黑", 16, 0);
	wMButton15->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton15->setReleasedArg("鹦鹉喙羽病", 0x0, "文泉驿微米黑", 12, 0);
	wMButton15->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton16                  -----------------------------*/
	wMButton16 = new STTButton(p_rt, this, "wMButton16", 0);
	wMButton16->setMainArg(687, 50, 98, 48, false);
	wMButton16->setPressedArg("尿液尿酸分辨", 0x0, "文泉驿微米黑", 16, 0);
	wMButton16->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton16->setReleasedArg("尿液尿酸分辨", 0x0, "文泉驿微米黑", 12, 0);
	wMButton16->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton17                  -----------------------------*/
	wMButton17 = new STTButton(p_rt, this, "wMButton17", 0);
	wMButton17->setMainArg(786, 50, 98, 48, false);
	wMButton17->setPressedArg("便秘", 0x0, "文泉驿微米黑", 16, 0);
	wMButton17->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton17->setReleasedArg("便秘", 0x0, "文泉驿微米黑", 12, 0);
	wMButton17->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Button : wMButton18                  -----------------------------*/
	wMButton18 = new STTButton(p_rt, this, "wMButton18", 0);
	wMButton18->setMainArg(885, 50, 98, 48, false);
	wMButton18->setPressedArg("其他", 0x0, "文泉驿微米黑", 16, 0);
	wMButton18->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton18->setReleasedArg("其他", 0x0, "文泉驿微米黑", 12, 0);
	wMButton18->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);

	/*----------------------------- Panel : wMPanel1                     -----------------------------*/
	wMPanel1 = new STTPanel(p_rt, this, "wMPanel1");
	wMPanel1->setMainArg(0, 98, 1025, 501, 0);
	wMPanel1->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 255, 1, 0xc0c0c0);

	/*----------------------------- Button : wMButton19                  -----------------------------*/
	wMButton19 = new STTButton(p_rt, wMPanel1, "wMButton19", 0);
	wMButton19->setMainArg(1, 1, 70, 498, false);
	wMButton19->setPressedArg("《", 0x0, "文泉驿微米黑", 16, 0);
	wMButton19->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton19->setReleasedArg("《", 0x0, "文泉驿微米黑", 16, 0);
	wMButton19->setReleasedStyle(5, 0, 0xebebeb, 0x999999, 1, 0, 0x999999, 1, 0xebebeb);
	wMButton19->onEventHandler(Event::CLICKED, this, (EHandler) &Frm06::wMButton19_clk_cb);

	/*----------------------------- Button : wMButton20                  -----------------------------*/
	wMButton20 = new STTButton(p_rt, wMPanel1, "wMButton20", 0);
	wMButton20->setMainArg(953, 1, 70, 498, false);
	wMButton20->setPressedArg("》", 0x0, "文泉驿微米黑", 16, 0);
	wMButton20->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton20->setReleasedArg("》", 0x0, "文泉驿微米黑", 16, 0);
	wMButton20->setReleasedStyle(5, 0, 0xebebeb, 0x999999, 1, 0, 0x999999, 1, 0xebebeb);
	wMButton20->onEventHandler(Event::CLICKED, this, (EHandler) &Frm06::wMButton20_clk_cb);

	/*called after widget created.*/

	return; //createParts END
}

#include "util/StringUtil.h"
#include "util/FileUtil.h"

vector<string> getImages(string prefix) {
	/*wMButton1（刷新媒体列表）的点击事件*/
	vector<string> ret1;
	vector<string> paths;
#if __arm__
	paths.push_back("/customer/prm/res/pic");//搜索客户目录
#else
	paths.push_back("./res/pic");//搜索资源目录
#endif
	vector<KV_Str_Str> ret;
	for(string path: paths) {
		FileUtil::getPathContent(path,ret);//搜索，注意文件太多可能会慢
	}
	for(KV_Str_Str kv: ret) {
		string filepath = kv.v + "/" + kv.k;
		if(StringUtil::endWithNoCase(filepath, ".png") || StringUtil::endWithNoCase(filepath, ".jpg")) {
			if(StringUtil::startWith(kv.k, prefix)) {
				ret1.push_back(filepath);
			}
		}
	}
	return ret1;
}

static string currentPrefix = "0-";
static vector<string> currentVec;
static int currentIdx = 0;

void Frm06::onLoad() {
	currentVec = getImages(currentPrefix);
	if(currentVec.size()>0) {
		wMPanel1->setBgImg(currentVec[currentIdx]);
	}
}

bool Frm06::onClosing() {
	return true;
}

void Frm06::onDispose() {

}

void Frm06::wMButton19_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton19（《）的点击事件*/
	currentIdx--;
	if(currentIdx < 0) {
		currentIdx = currentVec.size() - 1;
	}
	wMPanel1->setBgImg(currentVec[currentIdx]);
}

void Frm06::wMButton20_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton20（》）的点击事件*/
	currentIdx++;
	if(currentIdx > currentVec.size() - 1) {
		currentIdx = 0;
	}
	wMPanel1->setBgImg(currentVec[currentIdx]);
}
